package cn.kgc.detail.service;

import cn.kgc.detail.mapper.DetailMapper;
import cn.kgc.detail.mapper.SortMapper;
import cn.kgc.detail.pojo.Detail;
import cn.kgc.detail.pojo.DetailExample;
import cn.kgc.detail.pojo.Sort;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class DetailServiceImpl implements  DetailService {

    @Resource
    DetailMapper detailMapper;

    @Resource
    SortMapper sortMapper;

    @Override
    public List<Detail> selectAll(String title, Integer sortid) {
        List<Detail> details=new ArrayList<>();
        if (sortid!=0){
            DetailExample example=new DetailExample();
            DetailExample.Criteria criteria=example.createCriteria();
            criteria.andSortidEqualTo(sortid);
                criteria.andTitleLike("%"+title+"%");
                details=detailMapper.selectByExample(example);
            } else{
        details=detailMapper.selectByExample(null);
        }
        return details;
    }

    @Override
    public List<Sort> selectAllSort() {
        return sortMapper.selectByExample(null);
    }

    @Override
    public Detail selectAllById(Integer id) {
        return detailMapper.selectByPrimaryKey(id);
    }

    @Override
    public Integer updateDetail(Detail detail) {
        return detailMapper.updateByPrimaryKeySelective(detail);
    }
}
